<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
   <link rel="stylesheet" type="text/css" href="css/mui.min.css"/>
</head>
<body>
    <!--头部-->
    <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">个人中心</h1>
    </header>
    <!--body部分-->
    <div class="mui-content">
        <ul class="mui-table-view">
           <li class="mui-table-view-cell">
								<a id="head" class="mui-navigate-right" href="clip">头像
								<span class="mui-pull-right head">
									<img class="head-img mui-action-preview" id="head-img1" src="images/logo.png"/ style="width: 30px;
    vertical-align: middle;">
								</span>
							</a>
							</li>
							<li class="mui-table-view-cell">
								<a>姓名<span class="mui-pull-right" id="uname">Hbuilder</span></a>
							</li>
							<li class="mui-table-view-cell">
								<a>HBuilder账号<span class="mui-pull-right">hbuilder@dcloud.io</span></a>
							</li>
						</ul>
						<ul class="mui-table-view">
							<li class="mui-table-view-cell">
								<a>QQ号<span class="mui-pull-right">88888888</span></a>
							</li>
							<li class="mui-table-view-cell">
								<a>手机号<span class="mui-pull-right">18601234567</span></a>
							</li>
							<li class="mui-table-view-cell">
								<a>邮箱地址<span class="mui-pull-right">hbuilder@dcloud.io</span></a>
							</li>				                        
        </ul>
<!--        <p style="text-align:center;width: 100%;background:#fff;line-height: 50px;height: 50px;"><button type="button" class="mui-btn mui-btn-danger mui-btn-outlined" id="btn">确定</button></p>
-->    </div>
    <script src="js/mui.js" type="text/javascript" charset="utf-8"></script>
     <script src="js/jquery.min.js"></script>
    <script>
    	var uname = window.localStorage.getItem('username');
		console.log(uname);
		$('#uname').html(uname);
		window.src='';
//  	mui(".mui-table-view-cell").on("tap", "#head", function() {
//  		window.location.href='clip.html'
//  	})
    	mui(".mui-table-view-cell").on("tap", "#head", function(e) {
			if(mui.os.plus){
				var a = [{
					title: "拍照"
				}, {
					title: "从手机相册选择"
				}];
				plus.nativeUI.actionSheet({
					title: "修改头像",
					cancel: "取消",
					buttons: a
				}, function(b) {
					switch (b.index) {
						case 0:
							break;
						case 1:
							getImage();
							break;
						case 2:
							galleryImg();
							break;
						default:
							break
					}
				})	
			}
			
		});
		//拍照
		function getImage() {
			mui.plusReady(function(){
	    	   //拍照功能
	    	   //1获取摄像头对象
	    	   var bc = plus.camera.getCamera(2);
	    	   //2调用摄像头对象里的方法
	    	   bc.captureImage(function(suc){
	    	   	//返回相对路径
	    	   	var src = plus.io.convertLocalFileSystemURL(suc);
	    	   	window.src = src;
	    	   	$('#head-img1').attr('src',src);
//	            console.log(src);	           
	    	   },function(err){
	    	   	  console.log(err.code);
	    	   	  console.log(err.message);
	    	   },{
	    	   	index:'2'
	    	   })
	        })
			return window.src;
		}
		//从手机相册中选择
		function galleryImg(){
				 mui.plusReady(function(){
		   	   	//pick方法
			    	plus.gallery.pick(function(success){
//			    	      console.log(success);
			    	      var src = success;
			    	      window.src = src;
			    	      mui.get('http://10.20.159.53:3000/clip',{username:uname,imgsrc:src},function(data){
							   console.log(data);	
							   console.log('111');
			             },'json')
			    	      $('#head-img1').attr('src',src);
			    	})			
			    	},function(err){
			    		console.log(err.code);
			    		console.log(err.message);
			    	},{
			    		multiple:true,
			    		maximum:1,
			    		onmaxed:function(){
			    			plus.nativeUI.alert('最多只能选择1张',function(){
			    				console.log('user pressed');
			    			},'提示','确定')
			    		},
			    		system:false
		    	});
    	   return window.src;    	
        }
	    console.log(window.src);
	     $('#btn').click(function(){
				
		 })	
		
    </script>
    <script type="text/javascript">
    mui.init()
    </script>
</body>
</html>
